package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import com.sky.vo.OrderVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.core.annotation.Order;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {

    public void insert(Orders orders) ;

    void insertDetailBatches(List<OrderDetail> orderDetailList);
    /**
     * 根据订单号查询订单
     * @param outTradeNo
     */
    @Select("select * from orders where number = #{outTradeNo}")
    Orders getByNumber(String outTradeNo);


    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);
    @Select("select * from orders where id = #{id}")
    Orders getById(Long id);

    @Select("select * from order_detail where order_id=#{id}")
    List<OrderDetail> findOrderDetailById(Long id);
    @Select("select * from orders where id=#{id}")
    Orders findById(Long id);
    @Delete("delete from orders where id=#{id}")
    void deleteById(Long id);
    @Select("select * from order_detail where order_id=#{id}")
    List<OrderDetail> getDetailByOrderId(Long id);
    Page<Orders> pageQuery(OrdersPageQueryDTO dto);
    @Select("select * from orders where pay_status = #{number} and order_time< #{time}")
    List<Orders> getByStatusAndOrdertimeLT(Integer number, LocalDateTime time);
    @Select("select count(*) from orders where status = #{toBeConfirmed}")
    Integer findByStatus(Integer toBeConfirmed);
}
